package x.y.z;

import java.util.Stack;

public class LeetCode_0232 {

}

class MyQueue {
    private Stack<Integer> stackOldest;
    private Stack<Integer> stackNewest;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        stackNewest = new Stack<>();
        stackOldest = new Stack<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        stackNewest.push(x);
    }

    private void shiftStacks() {
        if (stackOldest.isEmpty()) {
            while (!stackNewest.isEmpty()) {
                stackOldest.push(stackNewest.pop());
            }
        }
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        shiftStacks();
        return stackOldest.pop();
    }

    /**
     * Get the front element.
     */
    public int peek() {
        shiftStacks();
        return stackOldest.peek();
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return stackOldest.isEmpty() && stackNewest.isEmpty();
    }
}
